<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"/>
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
		<meta name="HandheldFriendly" content="true"/>
		<meta name="MobileOptimized" content="320"/>
		<title>扫描</title>
        <link rel="stylesheet" type="text/css" href="../css/mui.css"/>
		<style type="text/css">
#bcid {
	width: 100%;
	position: absolute;
	top: 0px;
	bottom: 44px;
	text-align: center;
}
.tip {
	color: #FFFFFF;
	font-weight: bold;
	text-shadow: 0px -1px #103E5C;
}
footer {
	width: 100%;
	height: 44px;
	position: absolute;
	bottom: 0px;
	line-height: 44px;
	text-align: center;
	color: #FFF;
}
.fbt {
	width: 50%;
	height: 100%;
	background-color: #FFCC33;
	float: left;
}
.fbt:active {
  	-webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.5);
	box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.5);
}
		</style>
	</head>
	<body style="background-color: #000000;">
		<div id="bcid">
			<div style="height:40%"></div>
			<p class="tip">...载入中...</p>
		</div>
		<footer>
			<div class="fbt" id="close">取　 消</div>
			<div class="fbt" id="select" >从相册选择二维码</div>
		</footer>
	</body>
	
   
    <script src="../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/mui.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/req.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		var scan = null;//扫描对象  
        mui.init();
		window.onload = function(){
			mui.init();
			 mui.plusReady(function () {  
			 	//扫描
			 	console.log("打开扫码")
				startRecognize(); 
	        }); 
	        //监听取消
	         g("close").addEventListener("tap",function(e){
							mui.back();
			})
	         //监听相册选择
			g("select").addEventListener("tap",function(e){
				scanPicture();
			})
			
		}
		function startRecognize(){  
           try{  
	            var filters;  
	            //自定义的扫描控件样式  
	            var styles = {frameColor: "#0000FF",scanbarColor: "#0000FF"};
	            //扫描控件构造  
				filters = [plus.barcode.QR, plus.barcode.CODE128, plus.barcode.EAN13, plus.barcode.EAN8];
	            scan = new plus.barcode.Barcode('bcid',filters,styles);  
	            scan.onmarked = onmarked;  
	            scan.onerror = onerror;  
	            scan.start();
         	}catch(e){  
            mui.alert("出现错误啦:\n"+e);  
            }  
          }
          function onerror(e){  
            miu.alert(e);  
        };  
        function onmarked( type, result ) {  
        	switch(type){
		    	case plus.barcode.QR:
		    	type = 'QR';
		    	break;
		    	case plus.barcode.EAN13:
		    	type = 'EAN13';
		    	break;
		    	case plus.barcode.EAN8:
		    	type = 'EAN8';
		    	break;
		    	default:
		    	type = '其它'+type;
		    	break;
		    }
		    result = result.replace(/\r\n/g, '');
            var text = '';  
            console.log(type);
            console.log(result);
            //获取父类对象
            var ws=plus.webview.currentWebview()
            var wo = ws.opener();
            //调用父类函数，只要父类有 这个函数
            wo.evalJS("setcard_number('"+ result +"');");
            //关闭
			mui.back();
        };    
        // 从相册中选择二维码图片   
        function scanPicture() {  
            plus.gallery.pick(function(path){  
                plus.barcode.scan(path,onmarked,function(error){  
                    plus.nativeUI.alert( "无法识别此图片" );  
                });  
            });  
        }  
		</script>
</html>
